package com.stbu;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.stbu.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@ResponseBody
public class JsonController {


    @RequestMapping("/testJson")
    public String genericJson() throws JsonProcessingException {
        List<User> list = new ArrayList<>();
        User user = new User();
        user.setId(002);
        user.setUsername("2023002");
        user.setPassword("002002");

        User user1 = new User();
        user1.setId(222);
        user1.setUsername("admin2222");
        user1.setPassword("pwd222");
        list.add(user);
        list.add(user1);

        ObjectMapper mapper = new ObjectMapper();
        return  mapper.writeValueAsString(list);
    }
}
